package com.jic.interaction.weCashier.controller;

import com.jic.interaction.cardCouponPlatform.common.utils.BeanUtils;
import com.jic.interaction.cardCouponPlatform.common.utils.RestResult;
import com.jic.interaction.weCashier.model.entity.*;
import com.jic.interaction.weCashier.model.vo.request.*;
import com.jic.interaction.weCashier.model.vo.response.*;
import com.jic.interaction.weCashier.service.PaymentSubmissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/acq/v2/wepay")
@Api(tags = " [支付接口]")
@Slf4j
//TODO
public class PaymentSubmissionController {

    @Resource
    PaymentSubmissionService paymentSubmissionService;

    /**
     * @Author gym
     * @Description  //TODO
     * @param paymentSubmissionRequest
     * @return 订单编号
     * @throws Exception
     */
    @ApiOperation(value = "支付提交")
    @PostMapping("/makeOrder")
    public RestResult<PaymentSubmissionResponse> addCardCouponPlatform(@RequestBody  PaymentSubmissionRequest paymentSubmissionRequest) throws Exception {
        PaymentSubmission paymentSubmission = new PaymentSubmission();
        BeanUtils.Copy(paymentSubmissionRequest, paymentSubmission);
        PaymentSubmissionResponse param = paymentSubmissionService.addPlaceAnOrder(paymentSubmission);
        return RestResult.success("0000", param);
    }

    /*
     * @Author chengpunan
     *@Package com.jic.interaction.cardCouponPlatform.controller
     *ClassName CardCouponPlatformController
     * @Description  //TODO
     * @Date 16:53 2020/11/11
     * @Param CardCouponPlatformRequest 采购商信息
     * @return 订单信息
     * @Version:1.0
     **/

    /**
     * @Author gym
     * @param paymentResultRequest
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "支付结果查询")
    @PostMapping("/makeOrderCheck")
    public RestResult<PaymentResultResponse> getOrderCheck(@RequestBody PaymentResultRequest paymentResultRequest) throws Exception {
        PaymentResult paymentResult = new PaymentResult();
        BeanUtils.Copy(paymentResultRequest, paymentResult);
        PaymentResultResponse placeAnOrder = paymentSubmissionService.getOrderCheck(paymentResult);
        PaymentResultResponse paymentResultResponse = new PaymentResultResponse();
//        BeanUtils.Copy(placeAnOrder, paymentResultResponse);
        if (paymentResultResponse == null) {
            return RestResult.error("9999", "接口未完善");
        }
        return RestResult.success("0000", paymentResultResponse);
    }


    /**
     * @Author gym
     * @param passwordFactorRequest
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "获取密码因子")
    @PostMapping("/getPwdFactor")
    public RestResult<PasswordFactorResponse> getPassword(@RequestBody PasswordFactorRequest passwordFactorRequest) throws Exception {
        PasswordFactor passwordFactor = new PasswordFactor();
        BeanUtils.Copy(passwordFactorRequest, passwordFactor);
        PasswordFactorResponse placeAnOrder = paymentSubmissionService.getPassWord(passwordFactor);
        PasswordFactorResponse passwordFactorResponse = new PasswordFactorResponse();
//        BeanUtils.Copy(placeAnOrder, passwordFactorResponse);
        if (passwordFactorResponse == null) {
            return RestResult.error("9999", "接口未完善");
        }
        return RestResult.success("0", passwordFactorResponse);
    }


    /**
     * @Author gym
     * @param refundRequest
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "退款")
    @PostMapping("/refundOrder")
    public RestResult<RefundResponse> refund(@RequestBody RefundRequest refundRequest) throws Exception {
        Refund refund = new Refund();
        BeanUtils.Copy(refundRequest, refund);
        RefundResponse placeAnOrder = paymentSubmissionService.deleteOrder(refund);
        RefundResponse refundResponse = new RefundResponse();
//        BeanUtils.Copy(placeAnOrder, refundResponse);
        if (refundResponse == null) {
            return RestResult.error("9999", "接口未完善");
        }
        return RestResult.success("0", refundResponse);
    }

    /**
     * @Author gym
     * @param selectRefundRequest
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "退款查询")
    @PostMapping("/refundOrderCheck")
    public RestResult<SelectRefundResponse> selectRefundOrder(@RequestBody SelectRefundRequest selectRefundRequest) throws Exception {
        SelectRefund selectRefund = new SelectRefund();
        BeanUtils.Copy(selectRefundRequest, selectRefund);
        SelectRefundResponse placeAnOrder = paymentSubmissionService.selectRefund(selectRefund);
        SelectRefundResponse selectRefundResponse = new SelectRefundResponse();
//        BeanUtils.Copy(placeAnOrder, selectRefundResponse);
        if (selectRefundResponse == null) {
            return RestResult.error("9999", "接口未完善");
        }
        return RestResult.success("0", selectRefundResponse);
    }

    /**
     * @Author gym
     * @param preOrderRequest
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "预下单")
    @PostMapping("/preMakeOrder")
    public RestResult<PreOrderResponse> preMakeOrder(@RequestBody PreOrderRequest preOrderRequest) throws Exception {
        PreOrder preOrder = new PreOrder();
        org.springframework.beans.BeanUtils.copyProperties(preOrderRequest, preOrder);
        PreOrderResponse placeAnOrder = paymentSubmissionService.insertPreOrder(preOrder);
        PreOrderResponse preOrderResponse = new PreOrderResponse();
//       BeanUtils.copyProperties(placeAnOrder, preOrderResponse);
        if (preOrderResponse == null) {
            return RestResult.error("9999", "接口未完善");
        }
        return RestResult.success("0000", preOrderResponse);
    }

    /**
     * @Author gym
     * @param selectPreOrderRequest
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "预下单查询")
    @PostMapping("/preMakeOrderCheck")
    public RestResult<SelectPreOrderResponse> preMakeOrderCheck(@RequestBody SelectPreOrderRequest selectPreOrderRequest) throws Exception {
        SelectPreOrder selectPreOrder = new SelectPreOrder();
        BeanUtils.Copy(selectPreOrderRequest, selectPreOrder);
        SelectPreOrderResponse placeAnOrder = paymentSubmissionService.selectPreOrder(selectPreOrder);
        SelectPreOrderResponse selectPreOrderResponse = new SelectPreOrderResponse();
//        BeanUtils.Copy(placeAnOrder, selectPreOrderResponse);
        if (selectPreOrderResponse == null) {
            return RestResult.error("9999", "接口未完善");
        }
        return RestResult.success("0", selectPreOrderResponse);
    }
}
